/* author: Mariana Horita
   mariana.horita@gmail.com
   file: A3E3.cs*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Resolucao
{
    public partial class A3E3 : Form
    {
        public A3E3()
        {
            InitializeComponent();
        }

        private void btInsert_Click(object sender, EventArgs e)
        {
            bool inserted = false;

            foreach (TreeNode tn in trvAgenda.Nodes)
            {
                if (tn.Text == mcCalendario.SelectionStart.ToShortDateString())
                {
                    if (tn.Nodes.Count == 4)
                    {
                        MessageBox.Show("Esta data já possui 4 compromissos!");
                        return;
                    }

                    tn.Nodes.Add(txtCompromisso.Text);
                    inserted = true;
                }
            }

            if (! inserted)
            {
                TreeNode tn = trvAgenda.Nodes.Add(mcCalendario.SelectionStart.ToShortDateString());

                tn.Nodes.Add(txtCompromisso.Text);
            }

            txtCompromisso.Clear();
        }

        private void trvAgenda_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Parent == null)
            {
                pgbPorcentagem.Value = e.Node.Nodes.Count;
            }
        }
    }
}
